<template>
  <div>
    添加分类
    <el-form
      style="width: 50%"
      :model="staff"
      ref="ruleFrom"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="分类名称" prop="catename">
        <el-input v-model="staff.catename"></el-input>
      </el-form-item>
      <el-form-item label="商品分类" prop="catenName">
        <el-cascader
          ref="cas"
          v-if="list.length"
          :options="list"
          :props="{ expandTrigger: 'hover', label: 'catename', value: 'id' }"
          @change="handleChange"
        >
        </el-cascader>
      </el-form-item>
      <el-form-item label="排序" prop="id">
        <el-input v-model="staff.id"></el-input>
      </el-form-item>
      <el-form-item label="级别" prop="fid">
        <el-input v-model="staff.fid"></el-input>
      </el-form-item>
      <!-- <el-form-item label="显示" prop="isShow" width="100">
        <el-input v-model="staff.isShow"></el-input>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" @click="postCate()">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { PostCate,GetCategory} from "@/api/produce";
export default {
  data() {
    return {
        staff: {
            fid:this.$route.query.fid,
            isShow:1,
            catename:'',
            show_home:"",
            orders:'',
            show_cate:'',
            icon:'',
            banner:'',
            description:''
        },
        list:[]
    };
    
  },
  created() {
      GetCategory()
      .then(res=>{
        this.list = res.data.list
      })
    },
  methods: {
    //添加商品分类
    postCate() {
      PostCate({...this.staff,fid:this.$route.query.fid}).then((res) => {
        if (res.data.code === 0) {
          this.$message({
            type: "success",
            message: "添加成功",
          });
        }
      });
    },
    handleChange(value) {
      // 获取选择的节点列表
      var nodes = this.$refs.cas.getCheckedNodes()
      // 更新要添加的商品分类id与名称
      this.staff.categoryId = nodes[0].value;
      this.staff.cateName = nodes[0].label;
      console.log(nodes, value, '1122');

    },
  },
};
</script>
